package com.animee.jiujiangdict;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;

import java.util.ArrayList;
public class IdentifyImgActivity extends AppCompatActivity {

    private ArrayList<String> wordlist;
    private ArrayAdapter<String> adapter;
    GridView gv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_identify_img);
        //获取上一个页面传递过来的数据
        Bundle bundle = getIntent().getExtras();
        wordlist = bundle.getStringArrayList("wordlist");  //数据源
        gv = findViewById(R.id.iden_gv);
        adapter = new ArrayAdapter<>(this, R.layout.item_search_pgv, R.id.item_sgv_tv, wordlist);
        gv.setAdapter(adapter);
        setGvListener();   //设置网格每一项的点击事件
    }
    private void setGvListener() {
        gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String word = wordlist.get(position);
                Intent intent = new Intent(IdentifyImgActivity.this, WordInfoActivity.class);
                intent.putExtra("zi",word);
                startActivity(intent);
            }
        });
    }
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iden_iv_back:
                finish();
                break;
        }
    }
}
